
import { defineStore } from "pinia"
import { doGet } from "@/config/http"
import { svc, getListPageSize, arrChangeTreeFn } from "@/config/common"

const initListStore = defineStore(
  'init',
  {
    state: () => ({
      // 公共
      userList: [],
      governmentList: [],
      organizationList: [],
      roleList: [],
      // 系统
      approveConfigList: [],
      approveList: [],
      permissionList: [],
      dictTypeList: [],
      cityList: [],
      // 预算
      thirdCatalogList: [],
      hotCatalogList: [],
      itemTypeList: [],
      itemRangeAllList: [],
      kpi3List: [],
      budgetCompetentList: [],
      projectOneList: [],
      catalogList: [],
      // 收支控制
      bankList: [],
      expenditureEconomicList: [],
      expenditureFiscalList: [],
      expenditureFunctionalList: [],
      expenditurePtypeList: [],
      expenditureSubjectList: [],
      expenditureFeetypeFileList: [],
      expenditureReimbursementItemFileList: [],
      accountList: [],
      expenditureApplicationList: [],
      businessCardList: [],
      expenditureKpiList: [],
      proceedsList: [],
      
      // 合同管理
      contractTypeList: [],
      contractCooperationList: [],
      contractFeetypeList: [],
      contractTemplateList: [],
      contractSignerList: [],
      contractFiletypeList: [],
    }),
    actions: {
      //公共数据
      async publicList() {
        let p1 = doGet(svc, '/user/page', {pageSize: getListPageSize()}, false)
        let p2 = doGet(svc, '/government/page', {pageSize: getListPageSize()}, false)
        let p3 = doGet(svc, '/organization/page', {pageSize: getListPageSize()}, false)
        let p4 = doGet(svc, '/role/page', {pageSize: getListPageSize()}, false)
        let resArray = await Promise.all([p1, p2, p3, p4])
        this.userList = resArray[0]['records']
        this.governmentList = resArray[1]['records']
        this.organizationList = resArray[2]['records']
        this.roleList = resArray[3]['records']
      },
      //系统管理
      async baseList() {
        let p1 = doGet(svc, '/customApprove/approveConfig', {}, false)
        let p2 = doGet(svc, '/approve/page', {pageSize: getListPageSize()}, false)
        let p3 = doGet(svc, '/permission/page', {pageSize: getListPageSize()}, false)
        let p4 = doGet(svc, '/dict-type/page', {pageSize: getListPageSize()}, false)
        let p5 = doGet(svc, '/region/page', {pageSize: getListPageSize()}, false)
        let resArray = await Promise.all([p1, p2, p3, p4, p5])
        this.approveConfigList = resArray[0]
        this.approveList = resArray[1]['records']
        this.permissionList = resArray[2]['records']
        this.dictTypeList = resArray[3]['records']
        this.cityList = resArray[4]['records']
        
      },
      // 预算控制
      async budgetList() {
        let p1 = doGet(svc, '/budget-third-catalog/page', {pageSize: getListPageSize()}, false)
        let p2 = doGet(svc, '/budget-hot-catalog/page', {pageSize: getListPageSize()}, false)
        let p3 = doGet(svc, '/budget-item-type/page', {pageSize: getListPageSize()}, false)
        let p4 = doGet(svc, '/budget-item-range/page', {pageSize: getListPageSize()}, false)
        let p5 = doGet(svc, '/budget-kpi/page', {pageSize: getListPageSize(), sortField: 'weight',sortType: 'asc'}, false)
        let p6 = doGet(svc, '/budget-competent/page', {pageSize: getListPageSize()}, false)
        let p7 = doGet(svc, '/budget-project-one/page', {pageSize: getListPageSize()}, false)
        let p8 = doGet(svc, '/budget-catalog/page', {state:'1',pageSize: getListPageSize()}, false)
        let resArray = await Promise.all([p1, p2, p3, p4, p5, p6, p7, p8])

        this.thirdCatalogList = resArray[0]['records']
        this.hotCatalogList = resArray[1]['records']
        this.itemTypeList = arrChangeTreeFn(resArray[2]['records']).reverse();
        this.itemRangeAllList = resArray[3]['records'].reverse();
        // 开支范围回显
        this.kpi3List = resArray[4]['records'].filter(item => item.level === 3).reverse()
        this.budgetCompetentList = resArray[5]['records']
        this.projectOneList = resArray[6]['records']
        this.catalogList = resArray[7]['records']
      },
      // 收支控制
      async expenditureList() {
        let p1 = doGet(svc, '/bank/page', {pageSize: getListPageSize()}, false)
        let p2 = doGet(svc, '/expenditure-economic/page', {pageSize: getListPageSize()}, false)
        let p3 = doGet(svc, '/expenditure-fiscal/page', {pageSize: getListPageSize()}, false)
        let p4 = doGet(svc, '/expenditure-functional/page', {pageSize: getListPageSize()}, false)
        let p5 = doGet(svc, '/expenditure-ptype/page', {pageSize: getListPageSize()}, false)
        let p6 = doGet(svc, '/expenditure-subject/page', {pageSize: getListPageSize()}, false)
        let p7 = doGet(svc, '/expenditure-feetype-file/page', {pageSize: getListPageSize()}, false) // 费用类型附件
        let p8 = doGet(svc, '/expenditure-reimbursement-item-file/page', {pageSize: getListPageSize()}, false)
        let p9 = doGet(svc, '/expenditure-account/page', {accountType: '2', pageSize: getListPageSize()}, false)
        let p10 = doGet(svc, '/expenditure-proceeds/page', {pageSize: getListPageSize()}, false)
        let p11 = doGet(svc, '/expenditure-business-card/page', {pageSize: getListPageSize()}, false)
        let p12 = doGet(svc, '/expenditure-kpi/page', {pageSize: getListPageSize()}, false)
        let p13 = doGet(svc, '/expenditure-application/page', {pageSize: getListPageSize()}, false)
        let resArray = await Promise.all([p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13])

        this.bankList = resArray[0]['records']
        // 经济分类
        this.expenditureEconomicList = resArray[1]['records']
        // 财政项目
        this.expenditureFiscalList = resArray[2]['records']
        // 功能分类
        this.expenditureFunctionalList = resArray[3]['records']
        // 项目类型
        this.expenditurePtypeList = resArray[4]['records']
        // 会计科目
        this.expenditureSubjectList = resArray[5]['records']
        // 报账费用类型
        this.expenditureFeetypeFileList = resArray[6]['records']
        // 报账单明细附件
        this.expenditureReimbursementItemFileList = resArray[7]['records']
        // 账户信息
        this.accountList = resArray[8]['records']
        // 收款单位
        this.proceedsList = resArray[9]['records']
        // 用户公务卡信息
        this.businessCardList = resArray[10]['records']
        // 指标单
        this.expenditureKpiList = resArray[11]['records']
        // 事前用款申请单
        this.expenditureApplicationList = resArray[12]['records']
      },
      // 合同管理
      async contractList() {
        let p1 = doGet(svc, '/contract-type/page', {pageSize: getListPageSize()}, false) // 合同类型
        let p2 = doGet(svc, '/contract-cooperation/page', {pageSize: getListPageSize()}, false) // 往来单位
        let p3 = doGet(svc, '/contract-feetype/page', {pageSize: getListPageSize()}, false) // 合同费用类型
        let p4 = doGet(svc, '/contract-template/page', {pageSize: getListPageSize()}, false) // 合同模版
        let p5 = doGet(svc, '/bank/page', {pageSize: getListPageSize()}, false) // 银行
        let p6 = doGet(svc, '/contract-signer/page', {pageSize: getListPageSize()}, false) // 签订人
        let p7 = doGet(svc, '/contract-filetype/page', {pageSize: getListPageSize()}, false) // 合同附件类型
        let resArray = await Promise.all([p1, p2, p3, p4, p5, p6, p7])
        this.contractTypeList = resArray[0]['records']
        this.contractCooperationList = resArray[1]['records']
        this.contractFeetypeList = resArray[2]['records']
        this.contractTemplateList = resArray[3]['records']
        this.bankList = resArray[4]['records']
        this.contractSignerList = resArray[5]['records']
        this.contractFiletypeList = resArray[6]['records']
      },
      // 数据更新
      async listUpdate(list, path) {
        let res = await doGet(svc, path, {pageSize: getListPageSize()}, false)
        this[list] = res['records']
      }
    },
    
  })

export default initListStore
